package net.tycmc.cty.ctyms.timejob.iems.job;

import java.util.HashMap;

import net.tycmc.cty.ctyms.timejob.function.monitore.CheckSelfAndReport;
import net.tycmc.cty.ctyms.timejob.function.monitore.ControlHandler;
import net.tycmc.cty.ctyms.timejob.function.monitore.HeartBeat;
import net.tycmc.cty.ctyms.timejob.iems.service.EffectivenessStatService;

import org.apache.commons.configuration.ConfigurationException;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.tycmc.functions.util.DynamicReadConfig;

public class EffectivenessStatJob extends QuartzJobBean {
	private EffectivenessStatService effectivenessStatService;
	private HashMap<String, Object> param;



	public EffectivenessStatService getEffectivenessStatService() {
		return effectivenessStatService;
	}



	public void setEffectivenessStatService(
			EffectivenessStatService effectivenessStatService) {
		this.effectivenessStatService = effectivenessStatService;
	}



	@Override
	protected void executeInternal(JobExecutionContext jobexecutioncontext)
			throws JobExecutionException {
		if(ControlHandler.isControl()){
			this.reportHeartBeat();
			this.checkSelf();
		}
		effectivenessStatService.startWork(false);
	}
	/**
	 * 上报心跳信号
	 **/
	private void reportHeartBeat() {
		HeartBeat hbeat = new HeartBeat();
		this.param = new HashMap<String,Object>();
		String parameterContent = "12";
		try {
			parameterContent = DynamicReadConfig.getConfigProperty("config.properties", "effectivenessStatKey");
		} catch (ConfigurationException e) {
			e.printStackTrace();
		}
		this.param.put("jobID", parameterContent);
		this.param.put("jobName", "时效统计");
		hbeat.produceAndReportHeateBeat(this.param);
	}
	/**
	 * 自检，如果自检未通过则进行报警
	 **/
	private void checkSelf() {
		CheckSelfAndReport csar = new CheckSelfAndReport();
		csar.checkIfFailReport(this.param);
	}

}
